home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4785 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: ssbunews.ih.att.com!not-for-mail
  2. From: bamford@marconi.ih.att.com (Harold E. Bamford)
  3. Newsgroups: comp.os.msdos.programmer,comp.lang.c
  4. Subject: Re: open vs fopen?
  5. Date: 7 Feb 1996 00:06:57 GMT
  6. Organization: AT&T Network Wireless Systems Business Unit
  7. Distribution: na
  8. Message-ID: <4f8qf1$h3b@ssbunews.ih.att.com>
  9. References: <uEYFxc9nX8WX083yn@mbnet.mb.ca>
  10. NNTP-Posting-Host: daneel.ih.att.com
  11.  
  12. In article <uEYFxc9nX8WX083yn@mbnet.mb.ca>,
  13. Nathan T. Wild <natewild@mbnet.mb.ca> wrote:
  14.  
  15. >In C, why would one use open and DOS int handles rather than fopen and
  16. >stdio file handles?
  17. >
  18. >Is there some speed advantage or differnet functionality?
  19.  
  20. open() is for raw I/O.  You use read(), write(), lseek(), ltell()
  21.  
  22. fopen() is for buffered I/O.  You can use fread(), fscanf(), fgets(),
  23. getchar(), putchar, fprint(), fwrite(), fseek(), ftell(), etc.
  24.  
  25. For certain applications, you can get away without buffering.  But
  26. often it is easier to do the programming if you don't have to worry
  27. about unneeded system calls and buffering gives you that.
  28.  
  29. Raw I/O is faster if you are, for instance, sucking the entire contents
  30. of a file into memory at once.
  31.  
  32. Buffered I/O tends to automatically include parts of the standard C
  33. library that you may not need (*printf* stuff).
  34.  
  35. It depends on your goal.  And usually the reasons for using one or the
  36. other are operating system independent.
  37.  
  38. -- Harold
  39.